home *** CD-ROM | disk | FTP | other *** search
- #include "xinternl.h"
- #include "dipoly.h"
- #include <conio.h>
- #include <mem.h>
-
- /*==================================================================
- XPOLYGON.CPP contains the code for polygon graphics using the
- device-independent polygon scan routines from Michael Abrash's
- Doctor Dobbs columns
- ===================================================================*/
-
- extern BYTE * pbVGABuffer;
- extern int ScrnLogicalByteWidth;
- extern BYTE abLeftClipPlaneMask[];
- extern BYTE abRightClipPlaneMask[];
- extern int TopClip;
- extern int BottomClip;
-
- struct VERTEX {
- int X;
- int Y;
- };
-
- inline void _HorizontalLine(
- xPageHandle_t wOffset,
- xScreenCoord_t iLeftX,
- xScreenCoord_t iY,
- int iLength,
- xColor_t iColor
- )
- {
- if ( iLength < 0 ) {
- return;
- }
- BYTE * pb = pbVGABuffer + wOffset + ( ScrnLogicalByteWidth * iY ) + iLeftX / 4;
- int iTemp;
- //do the left part of the line
- if ( iTemp = ( iLeftX & 3 ) ) {
- outp( SC_INDEX, 0x02 );
- outp( SC_INDEX + 1, abLeftClipPlaneMask[ iTemp ] );
- *pb++ = ( BYTE )iColor;
- iLength -= ( 4 - iTemp );
- }
- if ( iLength < 0 ) {
- return;
- }
- //the middle
- if ( iTemp = ( iLength >> 2 ) ) {
- outpw( SC_INDEX, 0x0f02 );
- iLength &= 3;
- memset( pb, iColor, iTemp );
- pb += iTemp;
- }
- //then the right part
- if ( iLength ) {
- outp( SC_INDEX, 0x02 );
- outp( SC_INDEX + 1, abRightClipPlaneMask[ iLength ] );
- *pb = ( BYTE )iColor;
- }
- }
-
-
- /*
- _DrawHLineList() draws a list of horizontal lines passed by the scanning
- routine.
- */
- void _DrawHLineList(
- xPageHandle_t pagPage,
- hLineList * phll,
- xColor_t colColor
- )
- {
- //clip our y coordinates
- int iStartLine = 0;
- int iLinesToDraw = phll->iLength;
- //clip top
- if ( TopClip > phll->iYStart ) {
- iStartLine = TopClip - phll->iYStart;
- iLinesToDraw -= iStartLine;
- }
- //clip bottom
- int iBottomLine = phll->iYStart + phll->iLength;
- if ( BottomClip < iBottomLine ) {
- iLinesToDraw -= ( iBottomLine - BottomClip );
- }
- //now draw our list
- hLine * phln = phll->phln;
- int iLineCounter = phll->iYStart;
- while ( iLinesToDraw-- ) {
- _HorizontalLine( pagPage, phln->iXStart, iLineCounter++, phln->iXEnd - phln->iXStart, colColor );
- ++phln;
- }
- }
-
- void x_triangle( /* Draw a triangle */
- int x0,
- int y0,
- int x1,
- int y1,
- int x2,
- int y2,
- xColor_t colColor,
- xPageHandle_t pagPage
- )
- {
- vertexListHeader vtl;
- vtl.iLength = 3;
- vertex avtx[ 3 ] = { { x0, y0 }, { x1, y1 }, { x2, y2 } };
- vtl.pvtx = avtx;
- hLineList * phll = phllScannedPolygon( &vtl, 0, 0 );
- if ( phll ) {
- _DrawHLineList( pagPage, phll, colColor );
- if ( phll->phln ) {
- delete( phll->phln );
- }
- }
- }
-
- void x_polygon( /* Draw a convex polygon */
- VERTEX * pvertices,
- int num_vertices,
- xColor_t colColor,
- xPageHandle_t pagPage
- )
- {
- vertexListHeader vtl;
- vtl.iLength = num_vertices;
- vtl.pvtx = ( vertex * )pvertices;
- hLineList * phll = phllScannedPolygon( &vtl, 0, 0 );
- if ( phll ) {
- _DrawHLineList( pagPage, phll, colColor );
- if ( phll->phln ) {
- delete( phll->phln );
- }
- }
- }
-